Page({
    data: {
        s:['https://assets.renrentuibao.com/web%2Fuploads%2Fimage%2Fstore_1%2F0a4094d849b8397b8e0f699e8a45ffb065317478.png','https://assets.renrentuibao.com/web%2Fuploads%2Fimage%2Fstore_1%2F0a4094d849b8397b8e0f699e8a45ffb065317478.png','https://assets.renrentuibao.com/web%2Fuploads%2Fimage%2Fstore_1%2F0a4094d849b8397b8e0f699e8a45ffb065317478.png'],
        contact_tel: "",
        show_customer_service: 0,
        order_status: {},
        is_distributor: '',
        currentIndex: 0,
        popular_goods:[]
    },
    onLoad: function (e) {
        getApp().page.onLoad(this, e);
        this.popular_goods()
    },
    /* 这里实现控制中间凸显图片的样式 */

handleChange: function (e) {
    this.setData({
    currentIndex: e.detail.current
    })
    },
    order_nums: function (e) {
        var p = this
        getApp().request({
            url: getApp().api.user.order_nums,
            success: function (t) {
                console.log(t)
                if (t.code == 0) {
                    p.setData({
                        order_status: t.data.order_count
                    })
                }
            }
        })
    },
    userInfo: function (e) {
        var tt = this
        getApp().core.login({
            success: function(e) {
                wx.setStorageSync('code', e.code)
            }
        });
        wx.getUserProfile({
            desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
            success: (res) => {
                console.log('12331', res)
                getApp().request({
                    url: getApp().api.passport.login, 
                    method: "post",
                    data: {
                        code: wx.getStorageSync('code'),
                        user_info: res.rawData,
                        encrypted_data: res.encryptedData,
                        iv: res.iv,
                        signature: res.signature,
                        recommend_id:wx.getStorageSync('recommender_id'),
                        source:wx.getStorageSync('source')
                    },
                    success: function (o) {
                        console.log(0)
                        getApp().core.hideLoading();
                        if (0 == o.code) {
                            tt.onShow()
                        }
                    },
                });
            },
        })
    },
    loadData: function (e) {
        var t = this;
        t.setData({
            store: getApp().core.getStorageSync(getApp().const.STORE)
        }), getApp().request({
            url: getApp().api.user.index,
            success: function (o) {
                if (0 == o.code) {
                    if ("my" == t.data.__platform) o.data.menus.forEach(function (e, t, a) {
                        "bangding" === e.id && o.data.menus.splice(t, 1, 0);
                    });
                    t.setData(o.data), getApp().core.setStorageSync(getApp().const.PAGES_USER_USER, o.data),
                        getApp().core.setStorageSync(getApp().const.SHARE_SETTING, o.data.share_setting),
                        getApp().core.setStorageSync(getApp().const.USER_INFO, o.data.user_info);
                }
            }
        });
    },
    onReady: function (e) {
        getApp().page.onReady(this);
    },
    onShow: function (e) {
        getApp().page.onShow(this);
        this.loadData();
        if (wx.getStorageSync('ACCESS_TOKEN')) {
            this.order_nums()
        }
        var o = getApp().getUser()
        if (o.is_distributor) {
            this.setData({
                is_distributor: o.is_distributor
            })
        };
        this.ssss()
    },
    popular_goods:function(e){
        var th = this
        var popular_goods = th.data.popular_goods
        getApp().request({
            url: getApp().api.default.popular_goods,
            data:{
                page:1
            },
            success: function (t) {
                console.log(t)
              if (t.code == 0) {
                for (var i = 0; i < t.data.list.length; i++) {
                    popular_goods.push(t.data.list[i])
                  }
                th.setData({
                    popular_goods:popular_goods
                })
              }
            },
            complete: function (t) {
              getApp().core.hideLoading();
            }
          });
    },
    ssss:function(e){
        var a  = this
        getApp().request({
            url: getApp().api.integral.index,
            data: {},
            success: function (t) {
              if (t.code == 0) {
                if (t.data.user == null) {
                  a.setData({
                    // banner_list: t.data.banner_list,
                    coupon_list: t.data.coupon_list,
                    catList: t.data.cat_list,
                    promotion: t.data.promotion,
                    page_url: t.data.promotion.page_url,
                    pro_url: t.data.promotion.pro_url,
                    surprise: t.data.activity,
                  })
                } else {
                  a.setData({
                    // banner_list: t.data.banner_list,
                    coupon_list: t.data.coupon_list,
                    integral: t.data.user.integral,
                    catList: t.data.cat_list,
                    promotion: t.data.promotion,
                    page_url: t.data.promotion.page_url,
                    pro_url: t.data.promotion.pro_url,
                    surprise: t.data.activity,
                    is_distributor: t.data.user.is_distributor
                  })
                }
              }
            },
            complete: function (t) {
              getApp().core.hideLoading();
            }
          });
    },
    gis:function(e){
        var id = e.currentTarget.dataset.id
        wx.navigateTo({
          url: '/pages/goods/goods?id=' + id,
        })
    },
    callTel: function (e) {
        var t = e.currentTarget.dataset.tel;
        getApp().core.makePhoneCall({
            phoneNumber: t
        });
    },
    apply: function (t) {
        if (wx.getStorageSync('ACCESS_TOKEN')) {
            var a = getApp().core.getStorageSync(getApp().const.SHARE_SETTING), o = getApp().getUser();
            //   1 == a.share_condition ? getApp().core.navigateTo({url: "/pages/add-share/index"}) : 0 != a.share_condition && 2 != a.share_condition ||
            (0 == o.is_distributor || 2 == o.is_distributor ? getApp().core.showModal({
                // title: "申请成为" + this.data.store.share_custom_data.words.share_name.name,
                title: '是否立即前往99特权推客申请页面',
                content: "是否前往？",
                success: function (e) {
                    e.confirm && (wx.navigateTo({
                        url: '/pages/Nineactivities/Nineactivities',
                    }))

                }
            }) : getApp().core.navigateTo({
                url: "/pages/add-share/index"
            })
            );
        } else {
            this.login()
        }

    },
    share_index: function (e) {
        wx.navigateTo({
            url: '/pages/share/index',
        })
    },
    verify: function (e) {
        getApp().core.scanCode({
            onlyFromCamera: !1,
            success: function (e) {
                getApp().core.navigateTo({
                    url: "/" + e.path
                });
            },
            fail: function (e) {
                getApp().core.showToast({
                    title: "失败"
                });
            }
        });
    },
    member: function () {
        getApp().core.navigateTo({
            url: "/pages/member/member"
        });
    },
    integral_mall: function (e) {
        var t, a;
        getApp().permission_list && getApp().permission_list.length && (t = getApp().permission_list,
            a = "integralmall", -1 != ("," + t.join(",") + ",").indexOf("," + a + ",")) && getApp().core.navigateTo({
                url: "/pages/tuibao-integral-mall/index/index"
            });
    },
    clearCache: function () {
        wx.showActionSheet({
            itemList: ["清除缓存"],
            success: function (e) {
                if (0 === e.tapIndex) {
                    wx.showLoading({
                        title: "清除中..."
                    });
                    getApp().getStoreData();
                    setInterval(function () {
                        wx.hideLoading();
                    }, 1e3);
                }
            }
        });
    },
    completemessage: function (e) {
        var t = this.data.__wxapp_img.cell, a = [t.cell_1.url, t.cell_2.url, t.cell_3.url, t.cell_4.url, t.cell_5.url];
        getApp().core.previewImage({
            current: a[0],
            urls: a
        });
    },
    login: function (e) {
        this.data.user_info.access_token || getApp().page.setUserInfoShow();
    }
});